package org.ahuanlien.crm.query;

import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Calendar;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter
@Setter
public class SalesQueryObject extends QueryObject{

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDate;

    private Long companyId;
    private Long productId;
    private String groupBy = "e.name";

    public static final Map<String,String> groupTypes = new LinkedHashMap<>();
    static{
        groupTypes.put("e.name","订货人员");
        groupTypes.put("p.name","货品名称");
        groupTypes.put("s.name","供应商");
        groupTypes.put("p.brand_name","品牌");
        groupTypes.put("DATE_FORMAT(bill.vdate,\'%Y-%m\')","订货日期(月)");
        groupTypes.put("DATE_FORMAT(bill.vdate,\'%Y-%m-%d\')","订货日期(日)");
    }

    public void setEndDate(Date date) {
        if (date == null) {
            return;
        }
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        this.endDate = calendar.getTime();
    }

}
